package com.bkd.dreams.client.event;

import com.bkd.dreams.client.volunteer.VolunteerDTO;
import com.google.gwt.cell.client.ActionCell;
import com.google.gwt.safehtml.shared.SafeHtmlBuilder;
import com.google.gwt.safehtml.shared.SafeHtmlUtils;

public class SignUpActionCell extends ActionCell<VolunteerEventDTO> {

	private VolunteerDTO volunteer = null;
	
	public SignUpActionCell(VolunteerDTO volunteer, Delegate<VolunteerEventDTO> delegate) {
		super("",delegate);
		this.volunteer = volunteer;
	}
	
	@Override
	public void render(Context context, VolunteerEventDTO value, SafeHtmlBuilder sb) {
	    if(userIsSignedUp(value)) {
	    	sb.append(SafeHtmlUtils.fromString("Un-Sign-Up"));
	    } else {
	    	sb.append(SafeHtmlUtils.fromString("Sign-Up"));
	    }
	}
	
	protected boolean userIsSignedUp(VolunteerEventDTO event) {
		boolean result = false;
		if (volunteer != null) {
			result = event.getVolunteers().contains(volunteer.getKey());
		}
		return result;
	}
}
